<template>
  <div>
    <el-card class="box-card">
      <div slot="header" style="text-align:left">
        <el-form :inline="true" :model="searchForm" class="demo-form-inline">
          <el-form-item >
            <el-input v-model="searchForm.key" placeholder="地块名称"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit">查询</el-button>
             <el-button type="primary" @click="add">添加</el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-table :data="farm" border style="width: 100%">
        <el-table-column prop="preImage" label="预览图" style="width: 50%">
             <template slot-scope="scope" >
                   <img width="50"  height="50" :src="scope.row.preImage" @click="showImage(scope.row)" />
              </template>
        </el-table-column>
        <el-table-column prop="name" label="地块名称" style="width: 20%"></el-table-column>
        <el-table-column prop="address" label="地址" style="width: 50%"></el-table-column>
        <el-table-column prop="legalPerson" label="地图类型" style="width: 50%">
             <template slot-scope="scope">
                 <span v-if="scope.row.mapType=='Baidu'">百度</span>
                <span v-else-if="scope.row.mapType=='Google'">Google</span>
                 <span v-else-if="scope.row.mapType=='Tianditu'">天地图</span>
                  <span v-else>其他</span>
            </template>
        </el-table-column>
          <el-table-column prop="acreage" label="面积km²" style="width: 20%"></el-table-column>
          <el-table-column prop="person" label="负责人" style="width: 50%"></el-table-column>
        <el-table-column prop="phone" label="电话" style="width: 50%"></el-table-column>
        <el-table-column label="操作" style="width: 10%">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="showImage(scope.row)">查看</el-button>
            <el-button type="text" size="small" @click="edit(scope.row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top:10px;">
        <el-pagination
          background
          @current-change="handleCurrentChange"
          :current-page.sync="pagenow"
          :page-size="pagesize"
          layout="total, prev, pager, next"
          :total="total"
        ></el-pagination>
      </div>
       <el-dialog title="预览" :visible.sync="imageShow">
           <img width="70%" :src="bigImageUrl" />
      </el-dialog>
    </el-card>
   

  </div>
</template>

<script>
import { farmSearch } from "@/libs/api.js";
export default {
  methods: {
    handleCurrentChange(p) {
      this.loadPage(p);
    },
    onSubmit() {
      this.pagenow = 1;
      this.loadPage();
    },
    loadPage() {
      var param = { pagesize: 10, pageno: this.pagenow,"key":this.searchForm.key};
      farmSearch(param).then(res => {
        this.farm = res.rows;
        this.total = res.total;
      });
    },
    edit(row){
      this.$router.push({"path":"/plant/farm/add",query:{"id":row.id}});
    },
    add(){
      this.$router.push({"path":"/plant/farm/add"});
    },
    //显示图片
    showImage(row){
        this.bigImageUrl=row.preImage;
        this.imageShow=true;
    }
  },
 
  mounted() {
    this.loadPage();
  },

  data() {
    return {
      farm: [],
      total: 0,
      pagenow: 1,
      pagesize: 10,
      imageShow:false,
      bigImageUrl:"",
      searchForm: {
        key: ""
      }
    };
  }
};
</script>